package com.monkeygroup.mygoplus.view.home.activity;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.HorizontalScrollView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.facebook.drawee.view.SimpleDraweeView;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.monkeygroup.mygoplus.R;
import com.monkeygroup.mygoplus.base.BaseActivity;
import com.monkeygroup.mygoplus.commit.thing.vo.PropertyCommitVO;
import com.monkeygroup.mygoplus.common.utils.LocalInfo;
import com.monkeygroup.mygoplus.common.utils.StringUtil;
import com.monkeygroup.mygoplus.common.utils.image.Images;
import com.monkeygroup.mygoplus.http.HttpModel;
import com.monkeygroup.mygoplus.http.PersonHttpModel;
import com.monkeygroup.mygoplus.http.RequestUrl;
import com.monkeygroup.mygoplus.http.ThingsHttpModel;
import com.monkeygroup.mygoplus.thing.vo.MyImageVO;
import com.monkeygroup.mygoplus.thing.vo.RentVO;
import com.monkeygroup.mygoplus.thing.vo.UserVO;
import com.monkeygroup.mygoplus.user.vo.PersonalNomalInfo;
import com.monkeygroup.mygoplus.user.vo.UserCollectVO;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by LCW on 2017/5/31.
 */

public class ThingsDetailActivity extends BaseActivity implements OnMapReadyCallback {



    public static void gotoActivity(Activity activity,String type,String parent,String modal,String carport) {

        Intent intent = new Intent(activity,
                ThingsDetailActivity.class);

        Bundle bundle = new Bundle();
        bundle.putSerializable("param", "");
        intent.putExtra("param", bundle);

        //1-租房，2-出售
        intent.putExtra("type", type);
        intent.putExtra("parent", parent);
        //
        intent.putExtra("modal", modal);
        intent.putExtra("carport", carport);

        activity.startActivityForResult(intent, 3);
    }

    private TextView txt_top,txtTitle, txtImgSize, txtPurpose, txtName, txtContact, txtAddr, txtSalePriceTitle,
            txtSaleprice, txtAreaTitlie, txtArea, txtStoreyTitle, txtStorey, txtCarpotHaveTitel, txtCarpotHave,
            txtLiftTitle, txtLift, txtFeeTitle, txtFee, txtFittingTitle, txtFitting, txtCompletedateTitle,
            txtCompletedate, txtTypeTitle, txtType, txtDirectionTitle, txtDirection, txtCommunityNameTitle,
            txtCommunityName, txtBalconys, txtRooms, txtToilets, txtHalls;
    private LinearLayout ll_detail_direction,ll_shopequip,ll_shopequip_content,ll_things_style,ll_detail_layouttype;
    private TextView txt_detail_direction_item,txt_detail_model_item,txt_detail_road_width_item,txt_detail_width_item;
    private CheckOverSizeTextView text_things_detail_desc;
    private Button btnThingsOpenTextOpen,btnThingsOpenTextClose;
    private LinearLayout linearLayoutThingsDescOpen,linearLayoutThingsDescClose,ll_collect;
    private HorizontalScrollView scrollView;
    private LinearLayout linear;

    private List<MyImageVO> imageVO;
    private RentVO propertyModel;
    private UserVO userVO;
    //請求
    private ThingsHttpModel httpThingsModel,httpThingsModel1;

    private ViewPager viewPager;
    private SimpleDraweeView[] mImageViews;
    private LayoutInflater mInflater;
    private LinearLayout linearLayoutThingsMap;

    //請求參數
    private Map<String, String> params;
    private PersonHttpModel personHttpModel;
    private StringBuffer url;

    private String type,parent,modal,carpot;
    private PropertyCommitVO vo = null;
    @Override
    public void setContentView() {
        setContentView(R.layout.activity_sell_house_detail);
        mInflater = LayoutInflater.from(this);
    }

    @Override
    public void initView() {
        txtTitle = (TextView) findViewById(R.id.txt_title);
        txtTitle.setText("出售物件");
        txt_top = (TextView) findViewById(R.id.txt_top);


        txtImgSize = (TextView) findViewById(R.id.viewPager_things_all);
        txtPurpose = (TextView) findViewById(R.id.text_things_detail_purpose);
        txtName = (TextView) findViewById(R.id.text_things_detail_name);
        txtContact = (TextView) findViewById(R.id.text_detail_contact);
        txtAddr = (TextView) findViewById(R.id.text_detail_addr);
        txtSalePriceTitle = (TextView) findViewById(R.id.text_things_detail_saleprice_title);
        txtSaleprice = (TextView) findViewById(R.id.text_things_detail_saleprice);
        txtAreaTitlie = (TextView) findViewById(R.id.text_things_detail_area_title);
        txtArea = (TextView) findViewById(R.id.text_things_detail_area);
        txtStoreyTitle = (TextView) findViewById(R.id.text_things_detail_storey_title);
        txtStorey = (TextView) findViewById(R.id.text_things_detail_storey);
        txtCarpotHaveTitel = (TextView) findViewById(R.id.text_things_detail_cartport_have_title);
        txtCarpotHave = (TextView) findViewById(R.id.text_things_detail_cartport_have);
        txtLiftTitle = (TextView) findViewById(R.id.text_things_detail_lift_title);
        txtLift = (TextView) findViewById(R.id.text_things_detail_lift);
        txtFeeTitle = (TextView) findViewById(R.id.text_things_detail_fee_title);
        txtFee = (TextView) findViewById(R.id.text_things_detail_fee);
        txtFittingTitle = (TextView) findViewById(R.id.text_things_detail_fitting_title);
        txtFitting = (TextView) findViewById(R.id.text_things_detail_fitting);
        txtCompletedateTitle = (TextView) findViewById(R.id.text_things_detail_completeyear_title);
        txtCompletedate = (TextView) findViewById(R.id.text_things_detail_completeyear);
        txtTypeTitle = (TextView) findViewById(R.id.text_things_detail_type_title);
        txtType = (TextView) findViewById(R.id.text_things_detail_type);
        txtDirectionTitle = (TextView) findViewById(R.id.text_things_detail_direction_title);
        txtDirection = (TextView) findViewById(R.id.text_things_detail_direction);
        txtCommunityNameTitle = (TextView) findViewById(R.id.text_things_detail_communityname_title);
        txtCommunityName = (TextView) findViewById(R.id.text_things_detail_communityname);
        txtBalconys = (TextView) findViewById(R.id.text_things_detail_balconys);
        txtRooms = (TextView) findViewById(R.id.text_things_detail_rooms);
        txtToilets = (TextView) findViewById(R.id.text_things_detail_toilets);
        txtHalls = (TextView) findViewById(R.id.text_things_detail_halls);
        text_things_detail_desc = (CheckOverSizeTextView) findViewById(R.id.text_things_detail_desc);
        btnThingsOpenTextOpen = (Button) findViewById(R.id.btn_things_open_text_open);
        linearLayoutThingsDescOpen = (LinearLayout) findViewById(R.id.linearLayout_things_desc_open);
        btnThingsOpenTextClose = (Button) findViewById(R.id.btn_things_open_text_close);
        linearLayoutThingsDescClose = (LinearLayout) findViewById(R.id.linearLayout_things_desc_close);
        ll_collect= (LinearLayout) findViewById(R.id.ll_collect);

        text_things_detail_desc.setOnOverLineChangedListener(new CheckOverSizeTextView.OnOverSizeChangedListener() {
            @Override
            public void onChanged(boolean isOverSize) {
                if(isOverSize){
                    text_things_detail_desc.setEllipsize(TextUtils.TruncateAt.valueOf("END"));
                    linearLayoutThingsDescOpen.setVisibility(View.VISIBLE);
                }
            }
        });
        btnThingsOpenTextOpen.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(text_things_detail_desc.isOverSize()){
                    text_things_detail_desc.displayAll();
                    linearLayoutThingsDescOpen.setVisibility(View.GONE);
                    linearLayoutThingsDescClose.setVisibility(View.VISIBLE);
                }else{
                    text_things_detail_desc.hide(15);
                }
            }
        });
        btnThingsOpenTextClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(text_things_detail_desc.isOverSize()){
                    text_things_detail_desc.displayAll();
                }else{
                    text_things_detail_desc.hide(15);
                    linearLayoutThingsDescOpen.setVisibility(View.VISIBLE);
                    linearLayoutThingsDescClose.setVisibility(View.GONE);
                }
            }
        });



        scrollView = (HorizontalScrollView) this.findViewById(R.id.horizontal_scrollView_things);
        linear = (LinearLayout) this.findViewById(R.id.linearlayout_things_scrollView);
        linearLayoutThingsMap = (LinearLayout) findViewById(R.id.linearLayout_things_map);
        initMap();

        //店面
        ll_detail_direction= (LinearLayout) findViewById(R.id.ll_detail_direction);
        txt_detail_direction_item= (TextView) findViewById(R.id.txt_detail_direction_item);
        txt_detail_model_item= (TextView) findViewById(R.id.txt_detail_model_item);
        txt_detail_road_width_item= (TextView) findViewById(R.id.txt_detail_road_width_item);
        txt_detail_width_item= (TextView) findViewById(R.id.txt_detail_width_item);

        //配置
        ll_shopequip= (LinearLayout) findViewById(R.id.ll_shopequip);
        ll_shopequip_content= (LinearLayout) findViewById(R.id.ll_shopequip_content);
        //格局
        ll_things_style= (LinearLayout) findViewById(R.id.ll_things_style);
        //坐向
        ll_detail_layouttype= (LinearLayout) findViewById(R.id.ll_detail_layouttype);


        Intent intent = this.getIntent();
        Bundle bundle =  intent.getExtras();
        type = bundle.getString("type");
        parent= bundle.getString("parent");
        modal= bundle.getString("modal");
        carpot= bundle.getString("carpot");

        imageVO = (List<MyImageVO>) getIntent().getBundleExtra("param").getSerializable("imgModel");
        propertyModel = (RentVO) getIntent().getBundleExtra("param").getSerializable("propertyModel");
        userVO = (UserVO) getIntent().getBundleExtra("param").getSerializable("userVO");


        url=new StringBuffer(RequestUrl.savepropertyUrl);
        String param="";
//        String param = (String) getIntent().getBundleExtra("param").getSerializable("param");
        if(imageVO==null){
            ll_collect.setVisibility(View.INVISIBLE);
            propertyModel = new RentVO();
            propertyModel.setLat(0);
            propertyModel.setLng(0);



            txt_top.setVisibility(View.VISIBLE);
            txt_top.setText("发布");


            if("2".equals(type)){
                //住宅
                if("1".equals(parent)||"3".equals(parent)||"4".equals(parent)){
                    vo = LocalInfo.getHouseProperty(ThingsDetailActivity.this,modal);
                    ll_things_style.setVisibility(View.VISIBLE);
                }
                //店面
                else if("2".equals(parent)){

                    vo=LocalInfo.getShopProperty(ThingsDetailActivity.this,modal);
                    ll_things_style.setVisibility(View.GONE);

                    ll_detail_layouttype.setVisibility(View.GONE);

                    ll_detail_direction.setVisibility(View.VISIBLE);
                    ll_shopequip.setVisibility(View.VISIBLE);
                    ll_shopequip_content.setVisibility(View.VISIBLE);
                }
                //車位
                else if("5".equals(parent)){

                   // vo=LocalInfo.getCarportProperty(ThingsDetailActivity.this,modal);
                    ll_things_style.setVisibility(View.GONE);
                }
                //土地
                else if("6".equals(parent)){
                    vo= LocalInfo.getLandProperty(ThingsDetailActivity.this,modal);
                    ll_things_style.setVisibility(View.GONE);

                }

                param = "?area="+String.valueOf(vo.getProperty_area())+"&modal="+vo.getProperty_modal();
            }
            Log.e("modalmodal==",""+parent+"=="+modal+"::"+vo);
            String imgtype="";

            //圖片
            if(vo.getPropertyimg_sceimgtype()!=null){
                for(int i=0;i<vo.getPropertyimg_sceimgtype().length;i++){
//                Log.e("getPropertyie==",""+vo.getPropertyimg_sceimgtype()[i]);
                    if(!StringUtil.isBlank(vo.getPropertyimg_sceimgtype()[i])){
                        imgtype=vo.getPropertyimg_sceimgtype()[i];
                    }
                }
                if(vo.getPropertyimg_path1()!=null){

                    for(int i=0;i<vo.getPropertyimg_path1().length;i++) {
                        if (!StringUtil.isBlank(vo.getPropertyimg_path1()[i])) {
                            if(i==0){
                                url.append("?propertyimg_sceimgtype[]="+imgtype);
                            }
                            else{
                                url.append("&propertyimg_sceimgtype[]="+imgtype);
                            }

                            url.append("&propertyimg_path1[]="+vo.getPropertyimg_path1()[i]);
                            url.append("&propertyimg_path3[]="+vo.getPropertyimg_path1()[i]);
                            url.append("&propertyimg_path4[]="+vo.getPropertyimg_path1()[i]);
                            url.append("&propertyimg_width[]="+vo.getPropertyimg_width()[i]);
                            url.append("&propertyimg_height[]="+vo.getPropertyimg_height()[i]);
                            url.append("&propertyimg_size[]="+vo.getPropertyimg_size()[i]);
                            url.append("&propertyimg_name[]="+vo.getPropertyimg_name()[i]);

                        }
                    }
                }

                for(int i=0;i<vo.getPropertyimg_sceimgtype().length;i++) {
                    if (!StringUtil.isBlank(vo.getPropertyimg_sceimgtype()[i])) {



                    }
                }
            }


            //初始化图片
            imageVO = new ArrayList<>();
            String[] imgpath = vo.getPropertyimg_path1();
            if(imgpath!=null && imgpath.length!=0){

                for(int i=0;i<imgpath.length;i++){

                    MyImageVO imgvo = new MyImageVO();
                    imgvo.setPath3(imgpath[i]);
                    imageVO.add(imgvo);

                }
            }
//            vo.setPropertyimg_path3(vo.getPropertyimg_path1());
//            vo.setPropertyimg_path4(vo.getPropertyimg_path1());


            setImage(imageVO);


            vo.setProperty_sale(1);
            getThingsInfo(vo);

            PersonalNomalInfo user = LocalInfo.getUserInfo(ThingsDetailActivity.this);
            vo.setUser(String.valueOf(user.getSeq()));
            params = new HashMap<String, String>();
            vo.toMap(params);

            txt_top.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {


                    personHttpModel.requestUserLogin();
                }
            });
        }
        else{
            ll_collect.setVisibility(View.VISIBLE);
            txt_top.setVisibility(View.INVISIBLE);
            setImage(imageVO);
            setThingsInfo(propertyModel);
            setUserInfo(userVO);

             param = "?area="+propertyModel.getArea()+"&modal="+propertyModel.getModal();

            ll_collect.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                    UserCollectVO vo = new UserCollectVO();
                    vo.setPhone(userVO.getTel());
                    vo.setCollectSeq(String.valueOf(propertyModel.getSeq()));
                    LocalInfo.saveUserCollectInfo(ThingsDetailActivity.this,vo);
                }
            });

        }
        initHorizontalScrollViewRequest(param);
        httpThingsModel1.requestThings();
    }

    @Override
    public void setListener() {

    }

    @Override
    public void doEvent() {

    }

    private void setImage(List<MyImageVO> imgModel) {
        List<String> imgs = new ArrayList<>();
        for (MyImageVO vo : imgModel) {
            if (vo.getCover() != 1) {
                imgs.add(vo.getPath3());
            }
        }
        viewPager = (ViewPager) findViewById(R.id.viewPager_things_all_img);
        mImageViews = new SimpleDraweeView[imgs.size()];
        for (int i = 0; i < imgs.size(); i++) {
            final SimpleDraweeView imageView = new SimpleDraweeView(this);
            mImageViews[i] = imageView;
            Images.with(this).load(Uri.parse(imgs.get(i).toString())).into(imageView);
        }

        viewPager.setAdapter(new MyAdapter());
        if(mImageViews.length==0){
            txtImgSize.setText(0 + "/" + mImageViews.length);
        }else{
            txtImgSize.setText(1 + "/" + mImageViews.length);
        }
        viewPager.setCurrentItem(0);
        viewpagerListener();
        //设置ViewPager的默认项, 设置为长度的100倍，这样子开始就能往左滑动  
        //viewPager.setCurrentItem((mImageViews.length)*100);
    }

    private void viewpagerListener() {
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageSelected(int arg0) {
                txtImgSize.setText((arg0 + 1) + "/" + mImageViews.length);
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {

            }

            @Override
            public void onPageScrollStateChanged(int arg0) {

            }
        });
    }

    class MyAdapter extends PagerAdapter {

        @Override
        public int getCount() {
            return mImageViews.length;
        }

        @Override
        public boolean isViewFromObject(View arg0, Object arg1) {
            return arg0 == arg1;
        }

        @Override
        public void destroyItem(View container, int position, Object object) {
            ((ViewPager) container).removeView(mImageViews[position % mImageViews.length]);
        }

        /**
         * 载入图片进去，用当前的position 除以 图片数组长度取余数是关键
         */
        @Override
        public Object instantiateItem(View container, int position) {
            ((ViewPager) container).addView(mImageViews[position % mImageViews.length], 0);
            return mImageViews[position % mImageViews.length];
        }

    }

    private void setThingsInfo(RentVO propertyModel) {
        txtPurpose.setText(propertyModel.getPurpose());
        txtName.setText(propertyModel.getName());
        txtAddr.setText(propertyModel.getAddr());
        txtSalePriceTitle.setText("售價");
        txtSaleprice.setText(propertyModel.getSaleprice() + " 萬");
        txtAreaTitlie.setText("坪數");
        txtArea.setText(propertyModel.getLawnarea() + " 坪");
        txtStoreyTitle.setText("樓層");
        txtStorey.setText(propertyModel.getStorey());
        txtCarpotHaveTitel.setText("車位");
        txtCarpotHave.setText(propertyModel.getCartport_have() == 0 ? "無" : "有");
        txtLiftTitle.setText("電梯");
        txtLift.setText(propertyModel.getLift() == 0 ? "無" : "有");
        txtFeeTitle.setText("管理費");
        txtFee.setText(propertyModel.getFee() + "元/坪");
        txtFittingTitle.setText("裝修");
        txtFitting.setText(propertyModel.getFitting());
        txtCompletedateTitle.setText("完工日期");
        txtCompletedate.setText(propertyModel.getCompleteyear());
        txtType.setText(propertyModel.getPurpose());
        getDirection(propertyModel.getDirection(),txtDirection);
        txtCommunityName.setText(propertyModel.getCommunityname());
        txtBalconys.setText(propertyModel.getBalconys() + "陽臺");
        txtRooms.setText(propertyModel.getRooms() + "房");
        txtToilets.setText(propertyModel.getToilets() + "衛浴");
        txtHalls.setText(propertyModel.getHalls() + "聼");
        text_things_detail_desc.setText("精緻私密（全新）溫馨套房     " +
                "＋全天機器保全管控系統、自行刷卡進出安全私密均顧又不需管理費，水泥隔間；隱密性好" +
                "、寬頻網路、電視機、冰箱、第四台等...均免費使用、房間設備齊全：冷氣、床、書桌衣櫥、洗衣機、冷熱飲水機。" +
                "              " +
                "＋屋況乾淨、漂亮、生活機能超佳：郵局、ㄧ銀、富邦銀、全天24小時麥當勞營業及24小時無休餐飲小吃" +
                "＋屋況乾淨、漂亮、生活機能超佳：郵局、ㄧ銀、富邦銀、全天24小時麥當勞營業及24小時無休餐飲小吃..." +
                "＋屋況乾淨、漂亮、生活機能超佳：郵局、ㄧ銀、富邦銀、全天24小時麥當勞營業及24小時無休餐飲小吃..." +
                "＋屋況乾淨、漂亮、生活機能超佳：郵局、ㄧ銀、富邦銀、全天24小時麥當勞營業及24小時無休餐飲小吃...");
    }

    private void getThingsInfo(PropertyCommitVO propertyModel) {

        txtPurpose.setText(propertyModel.getProperty_purpose());
        txtName.setText(propertyModel.getProperty_name());
//        txtAddr.setText(propertyModel.getProperty());
        txtSalePriceTitle.setText("售價");
        txtSaleprice.setText(propertyModel.getProperty_saleprice() + " 萬");
        txtAreaTitlie.setText("坪數");
        txtArea.setText(propertyModel.getProperty_ownershiparea() + " 坪");
        Log.e("propertyMtyoor()==",""+propertyModel.getProperty_minfloor());
        txtStoreyTitle.setText("樓層");
        txtStorey.setText(String.valueOf(propertyModel.getProperty_minfloor()));
        txtCarpotHaveTitel.setText("車位");
        txtCarpotHave.setText(propertyModel.getProperty_carport() == 0 ? "無" : "有");
        txtLiftTitle.setText("電梯");
        txtLift.setText(propertyModel.getProperty_lift() == 0 ? "無" : "有");
        txtFeeTitle.setText("管理費");
        txtFee.setText(propertyModel.getProperty_fee() + "元/坪");
        txtFittingTitle.setText("裝修");
        getFitting(propertyModel.getProperty_fitting());
//        txtFitting.setText(propertyModel.getProperty_fitting());
//        txtCompletedateTitle.setText("完工日期");
//        txtCompletedate.setText(propertyModel.getProperty_completeyear());
        txtType.setText(propertyModel.getProperty_purpose());
        getDirection(propertyModel.getProperty_direction(),txtDirection);
        txtCommunityName.setText(String.valueOf(propertyModel.getProperty_community()));
        txtBalconys.setText(propertyModel.getProperty_balconys() + "陽臺");
        txtRooms.setText(propertyModel.getProperty_rooms() + "房");
        txtToilets.setText(propertyModel.getProperty_toilets() + "衛浴");
        txtHalls.setText(propertyModel.getProperty_halls() + "聼");
        //店面相关
        if("2".equals(parent)){
            getDirection(propertyModel.getProperty_direction(),txt_detail_direction_item);
            txt_detail_model_item.setText(propertyModel.getProperty_purpose());
            txt_detail_road_width_item.setText(propertyModel.getProperty_roadwidth()+"米");
            txt_detail_width_item.setText(propertyModel.getProperty_width() + "陽臺");
            txt_detail_width_item.setText(String.format("%s 米 × %s 米",propertyModel.getProperty_width(),propertyModel.getProperty_height()));

            setshopequip(propertyModel.getProperty_shopequip());
        }

    }

    private void setUserInfo(UserVO userVO) {
        txtContact.setText(userVO.getName() + " " + userVO.getTel());
    }

    //配置
    private void setshopequip(String shopequip){

        LinearLayout ll_shopequip_one= (LinearLayout) findViewById(R.id.ll_shopequip_one);
        TextView txt_shopequip_noe = (TextView)findViewById(R.id.txt_shopequip_noe);
        TextView txt_shopequip_two = (TextView)findViewById(R.id.txt_shopequip_two);
        TextView txt_shopequip_three = (TextView)findViewById(R.id.txt_shopequip_three);
        TextView txt_shopequip_four = (TextView)findViewById(R.id.txt_shopequip_four);
//
        LinearLayout ll_shopequip_two= (LinearLayout) findViewById(R.id.ll_shopequip_two);
        LinearLayout ll_split = (LinearLayout) findViewById(R.id.ll_split);
        TextView txt_shopequip_one = (TextView)findViewById(R.id.txt_shopequip_one);
        TextView txt_shopequip_ttwo = (TextView)findViewById(R.id.txt_shopequip_ttwo);
        TextView txt_shopequip_tthree = (TextView)findViewById(R.id.txt_shopequip_tthree);
        TextView txt_shopequip_tfour = (TextView)findViewById(R.id.txt_shopequip_tfour);



        Log.e("propertyModoopequip()",""+shopequip);
        if(!StringUtil.isBlank(shopequip)){
            Log.e("propertyModoopequip()","111111111111112222222");
            String[] equip = shopequip.split(",");
//            LinearLayout content1,content2 =null;
            if(equip.length==1){
                txt_shopequip_two.setVisibility(View.GONE);
                txt_shopequip_three.setVisibility(View.GONE);
                txt_shopequip_four.setVisibility(View.GONE);

                ll_shopequip_two.setVisibility(View.GONE);

            }
            else if(equip.length==2){
                txt_shopequip_three.setVisibility(View.GONE);
                txt_shopequip_four.setVisibility(View.GONE);

                ll_shopequip_two.setVisibility(View.GONE);
            }
            else if(equip.length==3){
                txt_shopequip_four.setVisibility(View.GONE);

                ll_shopequip_two.setVisibility(View.GONE);
            }
            else if(equip.length==4){
                ll_shopequip_two.setVisibility(View.GONE);
            }
            else if(equip.length==5){
                txt_shopequip_ttwo.setVisibility(View.GONE);
                txt_shopequip_tthree.setVisibility(View.GONE);
                txt_shopequip_tfour.setVisibility(View.GONE);
            }
            else if(equip.length==6){
                txt_shopequip_tthree.setVisibility(View.GONE);
                txt_shopequip_tfour.setVisibility(View.GONE);
            }
            else if(equip.length==7){
                txt_shopequip_tfour.setVisibility(View.GONE);
            }
            if(equip.length<5){
              //  ll_shopequip_one.removeAllViews();
                ll_shopequip_two.setVisibility(View.GONE);
               for(int i=0;i<equip.length;i++) {
                   Log.e("propertyModoopequip()",""+equip[i]);
                   if (!StringUtil.isBlank(equip[i])) {
                       if(i==0){
                           txt_shopequip_noe.setText(initShopequip(Integer.parseInt(equip[i])));
                       }
                       else if(i==1){
                           if(StringUtil.isBlank(equip[i])){
                               txt_shopequip_two.setVisibility(View.GONE);
                           }
                           else {
                               txt_shopequip_two.setText(initShopequip(Integer.parseInt(equip[i])));
                           }

                       }
                       else if(i==2){
                           if(StringUtil.isBlank(equip[i])){
                               txt_shopequip_three.setVisibility(View.GONE);
                           }
                           else {
                               txt_shopequip_three.setText(initShopequip(Integer.parseInt(equip[i])));
                           }

                       }
                       else if(i==3){
                           if(StringUtil.isBlank(equip[i])){
                               txt_shopequip_four.setVisibility(View.GONE);
                           }
                           else {
                               txt_shopequip_four.setText(initShopequip(Integer.parseInt(equip[i])));
                           }

                       }

                   }

               }
//                 content1 = new LinearLayout(ThingsDetailActivity.this);
//                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 220);
//                content1.setOrientation(LinearLayout.HORIZONTAL);
//                content1.setLayoutParams(lp);
            }
            else{
                ll_shopequip_two.setVisibility(View.VISIBLE);
                for(int i=0;i<equip.length;i++) {

                    if (!StringUtil.isBlank(equip[i])) {
                        if(i==0){

                            if(StringUtil.isBlank(equip[i])){
                                txt_shopequip_noe.setVisibility(View.GONE);
                            }
                            else {
                                txt_shopequip_noe.setText(initShopequip(Integer.parseInt(equip[i])));
                            }
                        }
                        else if(i==1){
                            if(StringUtil.isBlank(equip[i])){
                                txt_shopequip_two.setVisibility(View.GONE);
                            }
                            else {
                                txt_shopequip_two.setText(initShopequip(Integer.parseInt(equip[i])));
                            }

                        }
                        else if(i==2){
                            if(StringUtil.isBlank(equip[i])){
                                txt_shopequip_three.setVisibility(View.GONE);
                            }
                            else {
                                txt_shopequip_three.setText(initShopequip(Integer.parseInt(equip[i])));
                            }

                        }
                        else if(i==3){
                            if(StringUtil.isBlank(equip[i])){
                                txt_shopequip_four.setVisibility(View.GONE);
                            }
                            else {
                                txt_shopequip_four.setText(initShopequip(Integer.parseInt(equip[i])));
                            }

                        }
                        else if(i==4){

                            if(StringUtil.isBlank(equip[i])){
                                txt_shopequip_one.setVisibility(View.GONE);
                            }
                            else {
                                txt_shopequip_one.setText(initShopequip(Integer.parseInt(equip[i])));
                            }
                        }
                        else if(i==5){

                            if(StringUtil.isBlank(equip[i])){
                                txt_shopequip_ttwo.setVisibility(View.GONE);
                            }
                            else {
                                txt_shopequip_ttwo.setText(initShopequip(Integer.parseInt(equip[i])));
                            }
                        }
                        else if(i==6){

                            if(StringUtil.isBlank(equip[i])){
                                txt_shopequip_tthree.setVisibility(View.GONE);
                            }
                            else {
                                txt_shopequip_tthree.setText(initShopequip(Integer.parseInt(equip[i])));
                            }
                        }
                        else if(i==7){

                            if(StringUtil.isBlank(equip[i])){
                                txt_shopequip_tfour.setVisibility(View.GONE);
                            }
                            else {
                                txt_shopequip_tfour.setText(initShopequip(Integer.parseInt(equip[i])));
                            }
                        }


                    }

                }
//                content1 = new LinearLayout(ThingsDetailActivity.this);
//                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 220);
//                content1.setLayoutParams(lp);
//
//                 content2 = new LinearLayout(ThingsDetailActivity.this);
//                LinearLayout.LayoutParams lp2 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, 220);
//                content2.setOrientation(LinearLayout.HORIZONTAL);
//                content2.setLayoutParams(lp2);
            }
//
//            for(int i=0;i<equip.length;i++){
//
//                if(!StringUtil.isBlank(equip[i])){
//                    Log.e("propertyModoopequip()",""+equip[i]);
//                    if("1".equals(equip[i])){
//                        if(i<4){
//                            initTextView(content1,"客梯");
//                        }
//                        else{
//                            initTextView(content2,"客梯");
//                        }
//                    }
//                    else if("2".equals(equip[i])){
//
//                        if(i<4){
//                            initTextView(content1,"貨梯");
//                        }
//                        else{
//                            initTextView(content2,"貨梯");
//                        }
//                    }
//                    else if("3".equals(equip[i])){
//
//
//                        if(i<4){
//                            initTextView(content1,"扶梯");
//                        }
//                        else{
//                            initTextView(content2,"扶梯");
//                        }
//                    }
//                    else if("4".equals(equip[i])){
//
//
//                        if(i<4){
//                            initTextView(content1,"暖氣");
//                        }
//                        else{
//                            initTextView(content2,"暖氣");
//                        }
//                    }
//                    else if("5".equals(equip[i])){
//
//                        if(i<4){
//                            initTextView(content1,"停車位");
//                        }
//                        else{
//                            initTextView(content2,"停車位");
//                        }
//                    }
//                    else if("6".equals(equip[i])){
//
//                        if(i<4){
//                            initTextView(content1,"水");
//                        }
//                        else{
//                            initTextView(content2,"水");
//                        }
//                    }
//                    else if("7".equals(equip[i])){
//
//                        if(i<4){
//                            initTextView(content1,"天然氣");
//                        }
//                        else{
//                            initTextView(content2,"天然氣");
//                        }
//                    }
//                    else if("8".equals(equip[i])){
//                        if(i<4){
//                            initTextView(content1,"網路");
//                        }
//                        else{
//                            initTextView(content2,"網路");
//                        }
//                    }
//                }
//            }
//            ll_shopequip_content.addView(content1);
//            if(content2!=null){
//                ll_shopequip_content.addView(content2);
//            }
        }



    }

    private String initShopequip(int shopequip){
        String equip = "";
       if(shopequip==1){
           equip="客梯";
       }
        else if(shopequip==2){
           equip="扶梯";
       }
       else if(shopequip==3){
           equip="暖氣";
       }
       else if(shopequip==4){
           equip="停車位";
       }
       else if(shopequip==5){
           equip="水";
       }
       else if(shopequip==6){
           equip="天然氣";
       }
       else if(shopequip==7){
           equip="網路";
       }
        return  equip;
    }

    //新建textview
    private void initTextView(LinearLayout ll,String content){

        TextView txt = new TextView(ThingsDetailActivity.this);
        LinearLayout.LayoutParams txtlp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        txtlp.setMargins(20,0,0,10);
        txt.setLayoutParams(txtlp);
        txt.setText(content);
        //分隔线
        LinearLayout split = new LinearLayout(ThingsDetailActivity.this);
        LinearLayout.LayoutParams splitlp = new LinearLayout.LayoutParams(1, 100);
        split.setBackgroundResource(R.color.split_line);
        split.setLayoutParams(splitlp);

        ll.addView(txt);
        ll.addView(split);
    }
    private void getFitting(int property_fitting){

        //裝修
        switch (property_fitting) {
            case 1:
                txtFitting.setText("毛坯");
                break;
            case 2:
                txtFitting.setText("普通裝修");
                break;
            case 3:
                txtFitting.setText("精裝修");
                break;
            case 4:
                txtFitting.setText("豪華裝修");
                break;
            default:
                break;
        }

    }

    private void getDirection(int direction,TextView txtDirection) {
        switch (direction) {
            case 1:
                txtDirection.setText("座北朝南");
                break;
            case 2:
                txtDirection.setText("座南朝北");
                break;
            case 3:
                txtDirection.setText("座西朝東");
                break;
            case 4:
                txtDirection.setText("座東朝西");
                break;
            case 5:
                txtDirection.setText("座東北朝西南");
                break;
            case 6:
                txtDirection.setText("座東南朝西北");
                break;
            case 7:
                txtDirection.setText("座西南朝東北");
                break;
            case 8:
                txtDirection.setText("座西北朝東南");
                break;
            case 9:
                txtDirection.setText("其他");
                break;
            default:
                break;
        }
    }

    @Override
    public void onMapReady(GoogleMap googleMap) {
        LatLng positon = new LatLng(propertyModel.getLat(), propertyModel.getLng());
        googleMap.addMarker(new MarkerOptions().position(positon).title(""));
        googleMap.moveCamera(CameraUpdateFactory.newLatLng(positon));
        googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
            @Override
            public void onMapClick(LatLng latLng) {
                Bundle bundle = new Bundle();
                bundle.putSerializable("positon", propertyModel.getLat()+"-"+propertyModel.getLng());
                Intent intent = new Intent(ThingsDetailActivity.this,MapActivity.class);
                intent.putExtra("positon",bundle);
                startActivityForResult(intent,1);
            }
        });
    }

    private void initMap(){
        View view = mInflater.inflate(R.layout.map_things_detail,linearLayoutThingsMap, false);
        linearLayoutThingsMap.addView(view);
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map_thing_detail);
        mapFragment.getMapAsync(this);
    }

    public void initHorizontalScrollViewRequest(String param) {
        httpThingsModel1 = new ThingsHttpModel(RequestUrl.thingsbuyUrl + param,
                new ThingsHttpModel.SimpleOnHttpRequestListener() {
                    @Override
                    public void onRequestFinished(String resultCode, Integer timestamp) {

                    }

                    @Override
                    public void onRequestFinished(String resultCode, Object property, Object user, Object users, Object circuit, Object img) {
                        Gson gson = new Gson();
                        List<RentVO> propertys = gson.fromJson(gson.toJson(property), new TypeToken<List<RentVO>>() {
                        }.getType());

                        for (int i = 0; i < propertys.size(); i++) {
                            if(propertys.get(i).getSeq()==propertyModel.getSeq()){
                                continue;
                            }
                            createChildLinearLayout(propertys.get(i));
                        }

                    }

                    @Override
                    public void onBuildingRequestFinished(String resultCode, Object building, Object user, Object users, Object circuit, Object img) {

                    }

                    @Override
                    public void onCommunityRequestFinished(String resultCode, Object community, Object user, Object users, Object circuit, Object img) {

                    }
                }, true);


        personHttpModel = new PersonHttpModel(url.toString(),params,new PersonHttpModel.SimpleOnHttpRequestListener(){


            @Override
            public void onRequestFinished(String resultCode, Integer timestamp) {

            }

            @Override
            public void onRequestFinished(String resultCode, int seq, int isbind, String acc) {


            }

            @Override
            public void onRequestFinished(String resultCode, int seq, int flag, String flag_name, int secflag, String secflag_name) {

                Log.e("resultCoderesultCode===",""+"ERROR_OK".equals(resultCode));
                //請求成功
                if("ERROR_OK".equals(resultCode)){
                    Toast.makeText(ThingsDetailActivity.this, "发布成功",
                            Toast.LENGTH_SHORT).show();
                    txt_top.setVisibility(View.INVISIBLE);
                    LocalInfo.removeProperty(ThingsDetailActivity.this,vo);

                }
                else{

                    Toast.makeText(ThingsDetailActivity.this, "发布失败",
                            Toast.LENGTH_SHORT).show();
                }
            }

        },true);

    }

    private void createChildLinearLayout(final RentVO vo) {
        View view = mInflater.inflate(R.layout.item_things_detail_horizontalscrollview,linear, false);
        SimpleDraweeView imgView = (SimpleDraweeView) view.findViewById(R.id.img_things_horizontalscrollview);
        Images.with(this).load(Uri.parse(vo.getImg())).resize(180,180).into(imgView);
        TextView text1 = (TextView) view.findViewById(R.id.text_things_horizontalscrollview_1);
        text1.setText(vo.getName());
        TextView text2 = (TextView) view.findViewById(R.id.text_things_horizontalscrollview_2);
        text2.setText("NT$ "+vo.getSaleprice()+"/萬");
        TextView text3 = (TextView) view.findViewById(R.id.text_things_horizontalscrollview_3);
        text3.setText("坪數:"+vo.getLawnarea()+" 坪");
        TextView text4 = (TextView) view.findViewById(R.id.text_things_horizontalscrollview_4);
        text4.setText("層樓:"+vo.getStorey());
        linear.addView(view);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String param ="?seq="+vo.getSeq();
                initDetailRequest(param);
                httpThingsModel.requestThings();
            }
        });
    }

    public void initDetailRequest(String param) {
        httpThingsModel = new ThingsHttpModel(RequestUrl.getPropertyUrl + param,
                new ThingsHttpModel.SimpleOnHttpRequestListener() {
                    @Override
                    public void onRequestFinished(String resultCode, Integer timestamp) {

                    }

                    @Override
                    public void onRequestFinished(String resultCode, Object property, Object user, Object users, Object circuit, Object img) {
                        Gson gson = new Gson();
                        List<MyImageVO> imgModel = gson.fromJson(gson.toJson(img), new TypeToken<List<MyImageVO>>() {
                        }.getType());
                        RentVO propertyModel = gson.fromJson(gson.toJson(property), new TypeToken<RentVO>() {
                        }.getType());
                        UserVO userVO = gson.fromJson(gson.toJson(user), new TypeToken<UserVO>() {
                        }.getType());

                        Bundle bundle = new Bundle();
                        bundle.putSerializable("imgModel", (Serializable) imgModel);
                        bundle.putSerializable("propertyModel", propertyModel);
                        bundle.putSerializable("userVO", userVO);
                        Intent intent = new Intent(ThingsDetailActivity.this,ThingsDetailActivity.class);
                        intent.putExtra("param", bundle);
                        ThingsDetailActivity.this.startActivityForResult(intent, 3);
                    }

                    @Override
                    public void onBuildingRequestFinished(String resultCode, Object building, Object user, Object users, Object circuit, Object img) {

                    }

                    @Override
                    public void onCommunityRequestFinished(String resultCode, Object community, Object user, Object users, Object circuit, Object img) {

                    }
                }, true);
    }

}